package com.zzh.tree;

public class No226_invertTree {
    public static void main(String[] args) {
        No226Solution solution = new No226Solution();
        TreeNode treeNode = solution.invertTree(TreeNode.initTree());
        TreeNode.printTree(treeNode);
    }
}

class No226Solution {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        //创建一个新的变量就好了！！笨死了~
        TreeNode right = invertTree(root.right);
        TreeNode left = invertTree(root.left);
        //这种放在递归函数后面执行的属于递归到最深处才开始进行处理
        root.left = right;
        root.right = left;

        //nihaonihao
        return root;
    }
}
